﻿'========================================================================
'功能:人員群組管理
'作者:andy
'日期: 2011/2/8
'========================================================================

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Text
Imports System.Data
Partial Class WebForm_Manage_UserGroupMaintain
    Inherits BasePage
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = ActualUID
            hiDBName.Value = dbName
            lblTitle.Text = GetLocalResourceObject("lblTitle")

            If Not ChkProgramRight(1) Then '查詢
                gvGruopID.Visible = False
                btnQuery.Visible = False

            End If
            If Not ChkProgramRight(2) Then '編輯

                gvGruopID.Columns(0).Visible = False


            End If

            

        End If

    End Sub

    
    Protected Sub txtUID_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUID.TextChanged
        Dim bbl As OAMS.BBL.UsersBBL = New OAMS.BBL.UsersBBL()
        txtUserName.Text = bbl.GetUserName(txtUID.Text, dbName)
        If txtUserName.Text = "" Then 'UserID 不存在
            ShowMessageForAjax(txtUID, GetLocalResourceObject("errUIDNotExist"))
            txtUID.Focus()
        End If
        gvGruopID.EditIndex = -1 '換UserID將所屬群組資料清空
        gvGruopID.Visible = False
    End Sub

    Protected Sub gvGruopID_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvGruopID.RowUpdating
        Dim groupid1 As String = CType(gvGruopID.Rows(e.RowIndex).FindControl("ddlGroupID"), DropDownList).SelectedValue
        If txtUID.Text = "" Then 'UserID 不存在
            e.Cancel = True
            ShowMessageForAjax(txtUID, GetLocalResourceObject("errUIDEmpty"))
            Exit Sub
        End If
        If groupid1 = "" Then '群組沒有選
            e.Cancel = True
            ShowMessageForAjax(txtUID, GetLocalResourceObject("errGroupIDEmpty"))

            Exit Sub

        End If

        Dim bl As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        If bl.GroupMemberIsExist(groupid1, txtUID.Text, dbName) Then 'GroupMember資料已存在
            e.Cancel = True
            ShowMessageForAjax(txtUID, GetLocalResourceObject("errUIDExist"))
            Exit Sub
        End If
        '不知什麼原因直接用gridview的功能無法新增資料到DB中(UID1為NULL),所以用程式
        bl.InsertGroupMember(groupid1, txtUID.Text, hiUID.Value, dbName)
        e.Cancel = True
        gvGruopID.EditIndex = -1
        gvGruopID.DataBind()
    End Sub

    Protected Sub btnUID_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUID.Click
        gvGruopID.Visible = False '開窗'換UserID將所屬群組資料清空
        PopupFormForAjax(btnUID, "emp_no,emp_name", GetLocalResourceObject("ChnFieldsName"), "AUOREF.dbo.emp_data_all", dbName, "1,2", txtUID.ClientID & "," & txtUserName.ClientID, "directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes, width=500 ,left=200")
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Dim bbl As OAMS.BBL.UsersBBL = New OAMS.BBL.UsersBBL()
        txtUserName.Text = bbl.GetUserName(txtUID.Text, dbName)
        If txtUserName.Text = "" Then 'UserID 不存在
            ShowMessageForAjax(txtUID, GetLocalResourceObject("errUIDNotExist"))
            txtUID.Focus()
            Exit Sub
        End If


        gvGruopID.Visible = True '查詢所屬群組資料
        gvGruopID.DataBind()
    End Sub
End Class
